#!/usr/bin/env python
import os
import sys
import getopt
'''
picks up all files in unwraps/ and runs the matcher on each one against each other, outputting results to screen.
'''

optlist, args = getopt.getopt(sys.argv[1:],'ld')
matcher = 'matcher.exe'
debug = False

for o in optlist:
	if o[0] == '-l':
		matcher = './matcher'
	if o[0] == '-d':
		debug = True

files = [os.path.join('CSE30332-seg-data',x) for x in os.listdir('CSE30332-seg-data') if not os.path.isdir(x) and os.path.splitext(x)[1] in ['.tif', '.tiff', '.jpg', '.jpeg', '.pgm'] ]
files.sort()

if debug:
    for i in files:
        print i,
    sys.exit()

for f in files: print f, ',',
print ''
for probe in files:
    print "%s, " % probe,
    sys.stdout.flush()
    for gallery in files:
        args  = [matcher, '-g', gallery, '-p', probe]
        os.spawnv( os.P_WAIT, matcher, args )
    print ''
